package org.facilscrum.controller;

import org.facilscrum.beans.Issues;
import java.sql.Date; 
import java.io.Serializable;
import java.util.List;
import java.util.ArrayList;
import java.util.*;
import java.util.HashMap;
import java.util.Map;
import org.facilscrum.persistencia.IssuesPersistencia;
import org.facilscrum.interfaces.IController;
import org.facilscrum.generales.Mensajeria;


/**
*
*  @author
*/

public class IssuesController implements Serializable ,IController{
private static final long serialVersionUID = 1L;
private boolean withRelation= true;
public static Exception excepcion;


private Issues selectedissues;
private List<Issues> issueslist;


@Override
public boolean isWithRelation() {
    return withRelation;
}
@Override
public  void setWithRelation(boolean withRelation) {
    this.withRelation = withRelation;
}
public IssuesController(){
}

public Issues getSelectedIssues() {
 return selectedissues;
}

 public void setSelectedIssues(Issues selectedissues) {
 this.selectedissues = selectedissues;
}


public List<Issues> getIssueslist() {
  return issueslist;
}

 public void setIssueslist(List<Issues> issueslist) {
  this.issueslist = issueslist;
}
/*
*  getMensaje()
*   devuelve el mensaje encontrado...
*/
public String getMensaje() {
   String lexcepcion = excepcion.toString();
   if (lexcepcion.indexOf(":") != -1) {
       lexcepcion = lexcepcion.substring(lexcepcion.indexOf(":") + 1);
   }
  return lexcepcion;
}


/**
*
* insert()
*/

public boolean insert (Issues issues) {
try{
java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/facilscrum/properties/mensajes");
   if (validate(issues)) {
     if (findByPrimaryKey(issues)==null) {
         if (!IssuesPersistencia.insert(issues)) {
                 excepcion = IssuesPersistencia.excepcion;
          }
          else{
             return true;
           }
       }else{
               excepcion=new Exception(bundle.getString("msg.recordexists"));
            return false;
       }
    }
  }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"insert()");
  }
  return false;
}


/**
*
* update()
*/

public boolean update (Issues issues) {
try{
java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/facilscrum/properties/mensajes");
   if (validate(issues)) {
 if (IssuesPersistencia.exists(issues)) {
     if (!IssuesPersistencia.update(issues)) {
                excepcion = IssuesPersistencia.excepcion;
     }
     else{
            return true;
     }
   }else{
               excepcion=new Exception(bundle.getString("msg.nofoundprimarykey"));
            return false;
     }
  }
  }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"update()");
  }
  return false;
}


/**
*
* update(String sqlupdate)
*/

@Override
public boolean update(String sqlupdate) {
try{
     if (!IssuesPersistencia.update(sqlupdate)) {
                excepcion = IssuesPersistencia.excepcion;
     }
     else{
            return true;
     }
  }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"update()");
  }
  return false;
}


/**
*
* updatePrimaryKey()
*/

public boolean updatePrimaryKey (Issues issues_old , Issues issues) {
try{
java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/facilscrum/properties/mensajes");
   if (validate(issues_old)) {
 if (IssuesPersistencia.exists(issues_old)) {
     if (!IssuesPersistencia.updatePrimaryKey(issues_old,issues)) {
                excepcion = IssuesPersistencia.excepcion;
     }
     else{
            return true;
     }
   }else{
               excepcion=new Exception(bundle.getString("msg.nofoundprimarykey"));
            return false;
     }
  }
  }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"updatePrimaryKey()");
  }
  return false;
}


/**
*
* delete()
*/

public boolean delete (Issues issues) {
try{
java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/facilscrum/properties/mensajes");
 if (findByPrimaryKey(issues)!=null) {
     if (!IssuesPersistencia.delete(issues)) {
                excepcion = IssuesPersistencia.excepcion;
     }else{
            return true;
           }
   }else{
            excepcion=new Exception(bundle.getString("msg.nofoundprimarykey"));
            return false;
     }
  }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"delete()");
  }
  return false;
}


/**
*
* delete(String sqldelete)
*/

@Override
public boolean delete(String sqldelete) {
try{
     if (!IssuesPersistencia.delete(sqldelete)) {
                excepcion = IssuesPersistencia.excepcion;
     }else{
            return true;
           }
  }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"delete()");
  }
  return false;
}


/**
*
* deleteAll()
*/

@Override
public boolean deleteAll() {
try{
     if (!IssuesPersistencia.deleteAll()) {
                excepcion = IssuesPersistencia.excepcion;
     }
     else{
            return true;
     }
  }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"deleteAll()");
  }
  return false;
}


/**
*
* exists()
*/



public boolean exists(Issues issues) {
try{
   return IssuesPersistencia.exists(issues);
  }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"Exists()");
  }
 return false;
}


/**
*
* findPrimaryKey()
*/



public Issues findByPrimaryKey(Issues issues) {
try{
    this.selectedissues = IssuesPersistencia.findByPrimaryKey(issues);
    return selectedissues;
  }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"findByPrimaryKey()");
  }
 return null;
}


/**
*
* findByIdissues()
*/

public boolean findByIdissues(Issues issues) {
  try{
     if(issueslist != null){
        issueslist.removeAll(issueslist);
     }
     issueslist = IssuesPersistencia.findByIdissues(issues,withRelation) ;
     if (issueslist== null) {
                excepcion = IssuesPersistencia.excepcion;
       }
       else{
            return true;
            }
    }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"findByIdissues()");
    }
  return false;
  }


/**
*
* findByIdproyecto()
*/

public boolean findByIdproyecto(Issues issues) {
  try{
     if(issueslist != null){
        issueslist.removeAll(issueslist);
     }
     issueslist = IssuesPersistencia.findByIdproyecto(issues,withRelation) ;
     if (issueslist== null) {
                excepcion = IssuesPersistencia.excepcion;
       }
       else{
            return true;
            }
    }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"findByIdproyecto()");
    }
  return false;
  }


/**
*
* findByNumero()
*/

public boolean findByNumero(Issues issues) {
  try{
     if(issueslist != null){
        issueslist.removeAll(issueslist);
     }
     issueslist = IssuesPersistencia.findByNumero(issues,withRelation) ;
     if (issueslist== null) {
                excepcion = IssuesPersistencia.excepcion;
       }
       else{
            return true;
            }
    }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"findByNumero()");
    }
  return false;
  }


/**
*
* findByTitulo()
*/

public boolean findByTitulo(Issues issues) {
  try{
     if(issueslist != null){
        issueslist.removeAll(issueslist);
     }
     issueslist = IssuesPersistencia.findByTitulo(issues,withRelation) ;
     if (issueslist== null) {
                excepcion = IssuesPersistencia.excepcion;
       }
       else{
            return true;
            }
    }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"findByTitulo()");
    }
  return false;
  }


/**
*
* findByDescripcion()
*/

public boolean findByDescripcion(Issues issues) {
  try{
     if(issueslist != null){
        issueslist.removeAll(issueslist);
     }
     issueslist = IssuesPersistencia.findByDescripcion(issues,withRelation) ;
     if (issueslist== null) {
                excepcion = IssuesPersistencia.excepcion;
       }
       else{
            return true;
            }
    }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"findByDescripcion()");
    }
  return false;
  }


/**
*
* findByIdtipo()
*/

public boolean findByIdtipo(Issues issues) {
  try{
     if(issueslist != null){
        issueslist.removeAll(issueslist);
     }
     issueslist = IssuesPersistencia.findByIdtipo(issues,withRelation) ;
     if (issueslist== null) {
                excepcion = IssuesPersistencia.excepcion;
       }
       else{
            return true;
            }
    }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"findByIdtipo()");
    }
  return false;
  }


/**
*
* findByIdprioridad()
*/

public boolean findByIdprioridad(Issues issues) {
  try{
     if(issueslist != null){
        issueslist.removeAll(issueslist);
     }
     issueslist = IssuesPersistencia.findByIdprioridad(issues,withRelation) ;
     if (issueslist== null) {
                excepcion = IssuesPersistencia.excepcion;
       }
       else{
            return true;
            }
    }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"findByIdprioridad()");
    }
  return false;
  }


/**
*
* findByFecha()
*/

public boolean findByFecha(Issues issues) {
  try{
     if(issueslist != null){
        issueslist.removeAll(issueslist);
     }
     issueslist = IssuesPersistencia.findByFecha(issues,withRelation) ;
     if (issueslist== null) {
                excepcion = IssuesPersistencia.excepcion;
       }
       else{
            return true;
            }
    }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"findByFecha()");
    }
  return false;
  }


/**
*
* findByHora()
*/

public boolean findByHora(Issues issues) {
  try{
     if(issueslist != null){
        issueslist.removeAll(issueslist);
     }
     issueslist = IssuesPersistencia.findByHora(issues,withRelation) ;
     if (issueslist== null) {
                excepcion = IssuesPersistencia.excepcion;
       }
       else{
            return true;
            }
    }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"findByHora()");
    }
  return false;
  }


/**
*
* findByUsername()
*/

public boolean findByUsername(Issues issues) {
  try{
     if(issueslist != null){
        issueslist.removeAll(issueslist);
     }
     issueslist = IssuesPersistencia.findByUsername(issues,withRelation) ;
     if (issueslist== null) {
                excepcion = IssuesPersistencia.excepcion;
       }
       else{
            return true;
            }
    }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"findByUsername()");
    }
  return false;
  }


/**
*
* findByIdestatus()
*/

public boolean findByIdestatus(Issues issues) {
  try{
     if(issueslist != null){
        issueslist.removeAll(issueslist);
     }
     issueslist = IssuesPersistencia.findByIdestatus(issues,withRelation) ;
     if (issueslist== null) {
                excepcion = IssuesPersistencia.excepcion;
       }
       else{
            return true;
            }
    }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"findByIdestatus()");
    }
  return false;
  }


/**
*
* findByUsernameasignado()
*/

public boolean findByUsernameasignado(Issues issues) {
  try{
     if(issueslist != null){
        issueslist.removeAll(issueslist);
     }
     issueslist = IssuesPersistencia.findByUsernameasignado(issues,withRelation) ;
     if (issueslist== null) {
                excepcion = IssuesPersistencia.excepcion;
       }
       else{
            return true;
            }
    }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"findByUsernameasignado()");
    }
  return false;
  }


/**
*
* locateByParameters()
*/

public boolean locateByParameters(Map parametros) {
  try{
     if(issueslist != null){
        issueslist.removeAll(issueslist);
     }
     issueslist = IssuesPersistencia.locateByParameters(parametros,withRelation);
     if (issueslist== null) {
                excepcion = IssuesPersistencia.excepcion;
       }
       else{
            return true;
            }
    }catch(Exception ex){
       Mensajeria.MensajeError( ex ,"locateByParameters()");
  }
  return false;
}


/**
*
* Func(String funcion, String campo)
*/

@Override
public Double func(String funcion, String campo) {
  try{
     return IssuesPersistencia.func(funcion,campo);
    }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"func()");
  }
  return 0.0;
}


/**
*
* Double func(String funcion, String campo, String where)
*/

@Override
public Double func(String funcion, String campo,String where) {
  try{
     return IssuesPersistencia.func(funcion,campo,where);
    }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"Func()");
  }
  return 0.0;
}


/**
*
* count()
*/

@Override
public Integer count() {
  try{
     int x =IssuesPersistencia.count();
    return x;
    }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"count()");
  }
 return 0;
}


/**
*
* count(String sql)
*/

@Override
public Integer count(String sqlquery) {
  try{
     int x =IssuesPersistencia.count(sqlquery);
    return x;
    }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"count()");
  }
 return 0;
}


/**
*
* query()
*/

@Override
public boolean query(String query) {
  try{
     if(issueslist != null){
        issueslist.removeAll(issueslist);
     }
     issueslist = IssuesPersistencia.query(query,withRelation);
     if (issueslist== null) {
                excepcion = IssuesPersistencia.excepcion;
       }
       else{
            return true;
            }
    }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"query()");
  }
  return false;
}


/**
*
* orderby()
*/

@Override
public boolean orderby(String query) {
  try{
     if(issueslist != null){
        issueslist.removeAll(issueslist);
     }
     issueslist = IssuesPersistencia.orderby(query,withRelation);
     if (issueslist== null) {
                excepcion = IssuesPersistencia.excepcion;
       }
       else{
            return true;
            }
    }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"orderby()");
  }
  return false;
}


/**
*
* selectAll()
*/

@Override


public boolean selectAll() {
  try{
     if(issueslist != null){
        issueslist.removeAll(issueslist);
     }
     Map<String, String> parametros = new HashMap<>();
     issueslist = IssuesPersistencia.getListRecords(parametros,withRelation);
     if (issueslist== null) {
                excepcion = IssuesPersistencia.excepcion;
       }
       else{
            return true;
            }
    }catch(Exception ex){
       Mensajeria.MensajeError( ex ,"SelectAll()");
  }
            return false;
}


public boolean validate(Issues issues) {
 try{
   java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/facilscrum/properties/mensajes");

if (issues.getIdproyecto() == null || issues.getIdproyecto().toString().equals("")){
   excepcion=new Exception(bundle.getString("idproyecto")  + "  " + bundle.getString("msg.nonulo"));
  return false;
}
if (issues.getNumero() == null || issues.getNumero().toString().equals("")){
   excepcion=new Exception(bundle.getString("numero")  + "  " + bundle.getString("msg.nonulo"));
  return false;
}
if (issues.getTitulo() == null || issues.getTitulo().toString().equals("")){
   excepcion=new Exception(bundle.getString("titulo")  + "  " + bundle.getString("msg.nonulo"));
  return false;
}
if (issues.getDescripcion() == null || issues.getDescripcion().toString().equals("")){
   excepcion=new Exception(bundle.getString("descripcion")  + "  " + bundle.getString("msg.nonulo"));
  return false;
}
if (issues.getIdtipo() == null || issues.getIdtipo().toString().equals("")){
   excepcion=new Exception(bundle.getString("idtipo")  + "  " + bundle.getString("msg.nonulo"));
  return false;
}
if (issues.getIdprioridad() == null || issues.getIdprioridad().toString().equals("")){
   excepcion=new Exception(bundle.getString("idprioridad")  + "  " + bundle.getString("msg.nonulo"));
  return false;
}
if (issues.getFecha() == null || issues.getFecha().toString().equals("")){
   excepcion=new Exception(bundle.getString("fecha")  + "  " + bundle.getString("msg.nonulo"));
  return false;
}
if (issues.getHora() == null || issues.getHora().toString().equals("")){
   excepcion=new Exception(bundle.getString("hora")  + "  " + bundle.getString("msg.nonulo"));
  return false;
}
if (issues.getUsername() == null || issues.getUsername().toString().equals("")){
   excepcion=new Exception(bundle.getString("username")  + "  " + bundle.getString("msg.nonulo"));
  return false;
}
if (issues.getIdestatus() == null || issues.getIdestatus().toString().equals("")){
   excepcion=new Exception(bundle.getString("idestatus")  + "  " + bundle.getString("msg.nonulo"));
  return false;
}
   return true;
 }catch(Exception ex){
   Mensajeria.MensajeError(ex, "validate()");
  return false;

  }
}


}
